//
//  XmppHelper.m
//  MWXmppUnit
//
//  Created by liu nian on 3/18/16.
//  Copyright © 2016 Copyright © 2015年 http://iliunian.cn. All rights reserved.
//

#import "XmppHelper.h"
#import <MWXmppUnit/MWXmppUnit.h>
#import <UIKit/UIKit.h>
#import <CommonCrypto/CommonDigest.h>

@interface XmppHelper ()<MWXmppUnitConfigure>
@property (nonatomic, strong) MWXmppUnit *xmppUnit;

@end
@implementation XmppHelper
- (id)init{
    self = [super init];
    if (self) {
        [self.xmppUnit xmppConnect];
    }
    return self;
}

+ (XmppHelper *)sharedInstance
{
    static XmppHelper *sharedSingleton;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        sharedSingleton = [[XmppHelper alloc] init];
    });
    return sharedSingleton;
}

#pragma mark - MWXmppUnitConfigure
- (NSString *)xmppHostName{
    NSString * xmppIp = @"smartscene.com.cn";
    return xmppIp;
}
- (NSInteger)xmppHostPort{
    NSInteger port = 5222;
    return port;
}
- (NSString *)xmppUserName{
    NSString *mac = [[[self class] getUUIDAddress] uppercaseString];
    return [[NSString alloc] initWithFormat:@"%@@localhost.localdomain/Smack",mac];
    
}
- (NSString *)xmppPassword{
    NSString *mac = [[[self class] getUUIDAddress] uppercaseString];
    return mac;
}
- (void)xmppUnit:(MWXmppUnit *)xmppUnit didReceiveBodyMessage:(NSString *)bodyMessage{
    
}

// 获取设备MAC地址，AABBCCDDEEFF
+ (NSString *)getUUIDAddress{
    NSString *outstring = [[[UIDevice currentDevice] identifierForVendor] UUIDString];
    // 去掉中间的横线
    outstring = [outstring stringByReplacingOccurrencesOfString:@"-" withString:@""];
    return outstring;
}

#pragma mark - getter
- (MWXmppUnit *)xmppUnit{
    if (!_xmppUnit) {
        _xmppUnit = [[MWXmppUnit alloc] init];
        _xmppUnit.configureDelegate = self;
    }
    return _xmppUnit;
}
@end
